Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I7 parameters #14

Merged
merged 54 commits into from
Aug 13, 2020
Merged

I7 parameters #14

merged 54 commits into from
Aug 13, 2020

Conversation

eyvorchuk
Copy link
Contributor

This PR solves issue 7, which is to wrap the parameters module into a process, test it with pytest, and show it in a demo notebook. The only things that need to be done are to properly incorporate wps_tools (currently in progress) and test it using opendap files.

@eyvorchuk eyvorchuk marked this pull request as ready for review August 11, 2020 18:50
@eyvorchuk
Copy link
Contributor Author

I just added some commits to get the test and demo working. Could you guys try running them and let me know if there are any problems? Currently, the pytest will only work if called from the root osprey directory because the sample_parameter_config.cfg file uses file paths that are relative to that directory. You also might have to make the modification to share.py that Sangwon mentioned in his PR.

@eyvorchuk
Copy link
Contributor Author

Copy link
Contributor

@sum1lim sum1lim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pytest and demo-run are all successful except for test_wps_caps. Nice work!

import os
import logging
import json

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use wps_tools utils and io like you did in wps_parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna save that for a different PR since Nik already assigned me a separate issue for that.

Comment on lines 94 to 95
if request.inputs["version"][0].data:
from rvic import version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import statement in wps_convolution is placed at the top. Should we be matching the place it is imported?

process_step="process",
log_level=loglevel,
)
parameters(config, np)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While is good for now to pass config filepath right into RVIC parameters, I think it would be nice to implement a pathway for calling the function with a dictionary argument depending on the RVIC version. We could probably do this later in another PR. I will leave that decision up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add this once your config_builder PR is done.

@@ -11,5 +10,5 @@ def test_wps_caps():
"/wps:Capabilities" "/wps:ProcessOfferings" "/wps:Process" "/ows:Identifier"
)
assert sorted(names.split()) == [
"hello",
"convolution",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add parameters here

#-- Path to Pour Points File (char) --#
# A comma separated file of outlets to route to [lons, lats] - one coordinate pair per line (order not important)
# May optionally include a column [names] - which will (if not aggregating) be included in param file
FILE_NAME: tests/data/samples/sample_pour.txt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike RVIC convolution that uses a huge dataset, I think it is pretty reasonable to test RVIC parameters on local files. Good choice!

from osprey.processes.wps_parameters import Parameters


@pytest.mark.parametrize(("config"), [resource_filename(__name__, "data/samples/sample_parameter_config.cfg")])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to include a test case for opendap as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like, file paths inside the config file are opendap? I think I can make that work, but I'd have to delete a statement from rvic/parameters.py which I'm not sure is needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you elaborate more about deleting a statement in rvic/parameters.py? Which line are you referring to?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, unlike in rvic/convolution.py, rvic/parameters.py calls copy_inputs to copy the inputs to the CASEDIR. In doing so, it calls the copyfile function for each file path in the config file. Since the opendap urls don't exists as local files, this won't work. If I get rid of the initial call to copy_inputs, this won't be a problem, but I'd be removing functionality. The thing is, since this isn't done in rvic/convolution.py, I don't know how necessary this statement is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that is very interesting. So none of POUR_POINTS, UH_BOX, ROUTING, and DOMAIN supports opendap input? I think at least DOMAIN has to be taken from the server for proper use.

Copy link
Contributor

@sum1lim sum1lim Aug 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my experience, only POUR_POINTS should be taken from user's local directory. @corviday What do you think?

Copy link
Contributor

@nikola-rados nikola-rados left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small changes but I think this pretty much ready to go. I would wait to hear from @corviday before merging though.

Comment on lines -26 to -33
- name: Test with pytest (full)
if: github.ref == 'refs/heads/master'
run: |
py.test -v
- name: Test with pytest (fast)
if: github.ref != 'refs/heads/master'
run: |
py.test -m "not slow" -v
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd much rather these were just commented out rather than removed.

Comment on lines 94 to 95
if request.inputs["version"][0].data:
from rvic import version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point @sum1lim, it would be nice to have the files matching. I believe having the imports at the top is standard so we can move them there.

@eyvorchuk
Copy link
Contributor Author

Could you guys try running test_wps_parameters, once from the root osprey directory and once somewhere else? I modified the test to use a temporary config file which should make it more flexible.

@corviday
Copy link

Running test_wps_parameters from the root directory:

(venv) lzeman@pcic-2023:~/tmp/osprey-parameters/osprey$ pytest tests/test_wps_parameters.py 
=================================================================== test session starts ====================================================================
platform linux -- Python 3.6.9, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
rootdir: /home/lzeman/tmp/osprey-parameters/osprey, configfile: setup.cfg
plugins: notebook-0.6.0, nbval-0.9.6, flake8-1.0.6
collected 1 item                                                                                                                                           

tests/test_wps_parameters.py F                                                                                                                       [100%]

========================================================================= FAILURES =========================================================================
_____________________ test_parameters_local[/home/lzeman/tmp/osprey-parameters/osprey/tests/data/samples/sample_parameter_config.cfg] ______________________
Traceback (most recent call last):
  File "/home/lzeman/tmp/osprey-parameters/osprey/tests/test_wps_parameters.py", line 23, in test_parameters_local
    run_wps_process(Parameters(), params)
  File "/home/lzeman/tmp/osprey-parameters/osprey/venv/lib/python3.6/site-packages/wps_tools/testing.py", line 65, in run_wps_process
    assert_response_success(resp)
  File "/home/lzeman/tmp/osprey-parameters/osprey/venv/lib/python3.6/site-packages/pywps/tests.py", line 149, in assert_response_success
    assert len(success) == 1
AssertionError

running it from the osprey directory:

(venv) lzeman@pcic-2023:~/tmp/osprey-parameters/osprey/osprey$ pytest ../tests/test_wps_parameters.py 
=================================================================== test session starts ====================================================================
platform linux -- Python 3.6.9, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
rootdir: /home/lzeman/tmp/osprey-parameters/osprey, configfile: setup.cfg
plugins: notebook-0.6.0, nbval-0.9.6, flake8-1.0.6
collected 1 item                                                                                                                                           

../tests/test_wps_parameters.py F                                                                                                                    [100%]

========================================================================= FAILURES =========================================================================
_____________________ test_parameters_local[/home/lzeman/tmp/osprey-parameters/osprey/tests/data/samples/sample_parameter_config.cfg] ______________________
Traceback (most recent call last):
  File "/home/lzeman/tmp/osprey-parameters/osprey/tests/test_wps_parameters.py", line 23, in test_parameters_local
    run_wps_process(Parameters(), params)
  File "/home/lzeman/tmp/osprey-parameters/osprey/venv/lib/python3.6/site-packages/wps_tools/testing.py", line 65, in run_wps_process
    assert_response_success(resp)
  File "/home/lzeman/tmp/osprey-parameters/osprey/venv/lib/python3.6/site-packages/pywps/tests.py", line 149, in assert_response_success
    assert len(success) == 1
AssertionError

@eyvorchuk
Copy link
Contributor Author

@corviday
Copy link

I didn't know about the second set of modifications. After I made those, pytest test_wps_parameters.py worked from multipl directories.

@eyvorchuk
Copy link
Contributor Author

@corviday Is the PR ready for merging?

Copy link

@corviday corviday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I played around with the notebook, changing the pour point and looking at the results. The results seem good to me.

@eyvorchuk eyvorchuk merged commit ca1175d into master Aug 13, 2020
@eyvorchuk eyvorchuk deleted the i7-parameters branch August 13, 2020 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make running test_wps_parameters.py more flexible Wrap RVIC parameters module into wps
4 participants